package com.GDOU.controller;

import com.GDOU.bean.Teacher;
import com.GDOU.service.TeacherService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    //添加教师
    @PostMapping("/add.do")
    public Integer addTeacher(Teacher teacher){
        return teacherService.addTeacher(teacher);
    }

    //删除教师
    @GetMapping("/delete.do")
    public Integer deleteTeacher(@RequestParam("teaNum") String teaNum){
        return teacherService.deleteTeacher(teaNum);
    }

    //修改教师
    @GetMapping("/update.do")
    public Integer updateTeacher(Teacher teacher){
        return teacherService.updateTeacher(teacher);
    }

    //分页查询所有教师信息
    @GetMapping("/list.do")
    public PageInfo<Teacher> getTeacherPage(@RequestParam("pageNum") Integer pageNum){
        //获取教师的分页信息
        PageInfo<Teacher> page=teacherService.getTeacherPage(pageNum);
        //将分页数据返回
        return page;
    }

    //通过姓名获取教师信息
    @GetMapping("name.do")
    public Teacher getTeacherByName(@RequestParam("teaName")String teaName){
        return teacherService.getTeacherByName(teaName);
    }
}
